package com.yulongtian.offers.day202302;

/**
 * https://leetcode.cn/problems/count-complete-tree-nodes/
 * 可
 *
 * @author yulongTian
 * @create 2023-02-04 18:17
 */
public class Test04 {
    public static void main(String[] args) {

    }

    int ans;

    public int countNodes(TreeNode root) {
        ans = 0;
        pre(root);
        return ans;
    }

    //前序遍历
    public void pre(TreeNode root) {
        //根
        if (root != null) {
            ans++;
        } else {
            return;
        }
        //左
        pre(root.left);
        //右
        pre(root.right);
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
